﻿using MediatR;
using SupplyChain.Domain.Entities;
using SupplyChain.Infrastructure.Interface;
using SupplyChain.Write.API.Application.Command.PurchaseOrder;

namespace SupplyChain.Write.API.Application.CommandHandler.PurchaseOrder
{
    public class GetPurchaseCategoryHandler : IRequestHandler<GetPurchaseCategoryCommand, List<PurchaseCategory>>
    {
        private readonly IBaseRepository<PurchaseCategory> repository;

        public GetPurchaseCategoryHandler(IBaseRepository<PurchaseCategory> repository)
        {
            this.repository = repository;
        }

        public async Task<List<PurchaseCategory>> Handle(GetPurchaseCategoryCommand request, CancellationToken cancellationToken)
        {
            List<PurchaseCategory> categories = await repository.GetByWhereAsync(x => !x.IsDel);
            return await Task.FromResult(categories);
        }
    }
}
